function s1_generate_a_series_of_files(){
  for index in $(seq 1 100); do
      echo $index > "/tmp/new_file$index"
  done
}

function s2_list_4_files_in_long_format_about_account_and_group(){
  ls -l /etc/{passwd,group,shadow,gshadow} | sort -d
}

function s3_find_items_related_to_given_username(){
  awk -F: -v account="$1" '$1 == account { print $0 }' /etc/passwd /etc/shadow |sort -d
}

function s4_find_items_related_to_given_group_name(){
  awk -F: -v group="$1" '$1 == group { print $0 }' /etc/group /etc/shadow | awk '!seen[$0]++' | sort -d
}

#!/bin/bash
function s5_create_groups_for_given_group_names(){
  sudo groupadd rnd
  sudo groupadd itoperation
}

function s6_create_users_and_set_their_group_as_required(){
  sudo useradd -G rnd adam
  sudo useradd -G rnd bob
  sudo useradd -G itoperation calvin
  sudo useradd -G itoperation david
  sudo useradd -G rnd edward
}
function s7_change_users_shell(){
  sudo chsh -s /usr/bin/sh adam
  sudo chsh -s /usr/bin/sh edward
}
function s8_set_password_change_policy(){
  sudo chage -m 10 -M 60 -W 10 adam
  sudo chage -m 10 -M 60 -W 10 bob
  sudo chage -m 10 -M 60 -W 10 calvin
  sudo chage -m 10 -M 60 -W 10 david
  sudo chage -m 10 -M 60 -W 10 edward

}

function s9_set_password_for_five_users(){
  echo "adam:$1" | sudo chpasswd
  echo "bob:$2" | sudo chpasswd
  echo "calvin:$3" | sudo chpasswd
  echo "david:$4" | sudo chpasswd
  echo "edward:$5" | sudo chpasswd
}

function s10_lock_bobs_password(){
   passwd -l bob
}

#!/bin/bash
function s11_include_adam_into_wheel_group(){
   sudo usermod -aG wheel adam
   echo "adam ALL=(ALL) ALL" | sudo EDITOR='tee -a' visudo
   newgrp wheel
   sleep 2
}

function s12_change_files_permission(){
  directory="/tmp/"
  for i in {3..99..3};do
      filename="new_file${i}"
      filepath="${directory}/${filename}"
      if [ -f "$filepath" ];then
          echo "before chmod: $(ls -l "$filepath")"
          chmod 4640 "$filepath"
          echo "after chmod: $(ls -l "$filepath")"
      fi
  done
}

